package cn.iocoder.yudao.module.form.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.form.dataobject.FormChart;
import cn.iocoder.yudao.module.form.service.IFormChartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 图表Controller
 *
 * @author Fan KaiXiang
 * @date 2022-08-31
 */
@Api(tags = "a图表管理")
@RestController
@RequestMapping("/admin-api/form/chart")
public class FormChartController
{
    @Autowired
    private IFormChartService formChartService;

    /**
     * 查询图表列表
     */
//    @PreAuthorize("@ss.hasPermi('form:chart:list')")
    @ApiOperation(value = "获取图表列表", notes = "获取图表列表")
    @GetMapping("/list")
    public CommonResult<List<FormChart>> list(FormChart formChart)
    {
//        startPage();
        List<FormChart> list = formChartService.selectFormChartList(formChart);
        return success(list);
    }

    /**
     * 导出图表列表
     */
//    @PreAuthorize("@ss.hasPermi('form:chart:export')")
//    @Log(title = "图表", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, FormChart formChart)
//    {
//        List<FormChart> list = formChartService.selectFormChartList(formChart);
//        ExcelUtil<FormChart> util = new ExcelUtil<FormChart>(FormChart.class);
//        util.exportExcel(response, list, "图表数据");
//    }

    /**
     * 获取图表详细信息
     */
//    @PreAuthorize("@ss.hasPermi('form:chart:query')")
    @ApiOperation(value = "根据id获取图表", notes = "根据id获取图表")
    @GetMapping(value = "/{chartId}")
    public CommonResult<FormChart> getInfo(@PathVariable("chartId") Long chartId)
    {
        return success(formChartService.selectFormChartByChartId(chartId));
    }

    /**
     * 新增图表
     */
//    @PreAuthorize("@ss.hasPermi('form:chart:add')")
    @ApiOperation(value = "新增图表", notes = "新增图表")
    @PostMapping
    public CommonResult<Integer> add(@RequestBody FormChart formChart)
    {
        return success(formChartService.insertFormChart(formChart));
    }

    /**
     * 修改图表
     */
//    @PreAuthorize("@ss.hasPermi('form:chart:edit')")
    @ApiOperation(value = "修改图表", notes = "修改图表")
    @PutMapping
    public CommonResult<Integer> edit(@RequestBody FormChart formChart)
    {
        return success(formChartService.updateFormChart(formChart));
    }

    /**
     * 删除图表
     */
//    @PreAuthorize("@ss.hasPermi('form:chart:remove')")
    @ApiOperation(value = "删除图表", notes = "删除图表")
	@DeleteMapping("/{chartIds}")
    public CommonResult<Integer> remove(@PathVariable Long[] chartIds)
    {
        return success(formChartService.deleteFormChartByChartIds(chartIds));
    }
}
